Skip to content

Fix SST_Task_lock() when BASEPRI is zero - #8

Open
xbin-xu wants to merge 1 commit into
QuantumLeaps:mainfrom
xbin-xu:fix/task-lock-ineffective-when-basepri-zero
Open

xbin-xu wants to merge 1 commit into
QuantumLeaps:mainfrom
xbin-xu:fix/task-lock-ineffective-when-basepri-zero

Conversation

@xbin-xu

@xbin-xu xbin-xu commented Oct 18, 2026

Copy link
Copy Markdown

BASEPRI == 0 disables priority masking. The previous check (basepri_ > nvic_prio) is always false in that case, so SST_Task_lock() never writes BASEPRI. Every lock taken while BASEPRI is 0 is therefore a no-op, including nested locks; SST_Task_unlock() restores 0, so the next lock fails the same way.

Treat BASEPRI == 0 as the lowest priority in both the C and C++ ARM Cortex-M ports.

Fixes #7

BASEPRI == 0 disables priority masking. The previous check
(basepri_ > nvic_prio) is always false in that case, so SST_Task_lock()
never writes BASEPRI. Every lock taken while BASEPRI is 0 is therefore
a no-op, including nested locks; SST_Task_unlock() restores 0, so the
next lock fails the same way.

Treat BASEPRI == 0 as the lowest priority in both the C and C++ ARM
Cortex-M ports.

Fixes QuantumLeaps#7
@quantum-leaps

Copy link
Copy Markdown
Contributor

I'm sorry for my delayed response. The proposed change looks reasonable, but I didn't have a chance to verify on the target. Please do the verification step and submit along with the PR.

Thanks a lot for the contribution,
--Miro

@xbin-xu

xbin-xu commented Oct 22, 2026

Copy link
Copy Markdown
Author

Sorry for the late reply.

I only have an STM32F103C6 on hand, so I added an STM32F103C6
target to the blinky_button example in my fork and used it to verify the fix.

See test_priority_ceiling.md for the test results.

The test posts an event from Blinky1 to Blinky3 while Blinky1 holds
SST_Task_lock(3U), which makes the priority ceiling directly observable:

  • with the fix: Blinky3 runs only after Blinky1's critical section ends
    (D2 pulse after D5 falls)

    case1

  • with the legacy code: Blinky3 preempts immediately
    (D2 pulse before D5 falls)

    case2

The behavior is the same in Keil µVision simulator and on the real board.

Is this verification sufficient, or would you like me to test anything else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Does SST_Task_lock() need to handle basepri_ == 0?

2 participants